import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';

import 'package:smart_shop/utils/colorUtils.dart';

/// 订单收费
class OrderCharge extends StatefulWidget {
  const OrderCharge({Key? key}) : super(key: key);

  @override
  State<OrderCharge> createState() => _OrderChargeState();
}

class _OrderChargeState extends State<OrderCharge> {
  late int _singleSelectedIndex = -1;

  late int month = 0;

  late int price = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BrnAppBar(
          leading: GestureDetector(
            child: Icon(Icons.arrow_back, color: ColorUtils.fromHex('#212121')),
            onTap: () {
              Navigator.of(context).pop();
            },
          ),
          automaticallyImplyLeading: false,
          titleAlignment: Alignment.centerLeft,
          title: Container(
              alignment: Alignment.centerLeft,
              child: Text('订单收费',
                  style: TextStyle(
                      fontSize: 18,
                      fontFamily: 'Source Han Sans CN',
                      color: ColorUtils.fromHex('#212121'),
                      fontWeight: FontWeight.w500))),
          primary: true,
          backgroundColor: Colors.white),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        textDirection: TextDirection.ltr,
        children: [
          Container(
            height: 34,
            alignment: Alignment.center,
            child: Text('收费标准',
                style: TextStyle(
                    fontFamily: 'Source Han Sans CN',
                    fontWeight: FontWeight.normal,
                    fontSize: 18,
                    color: ColorUtils.fromHex('#002440'))),
          ),
          Padding(
            padding: const EdgeInsets.all(10),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  height: 54,
                  color: Colors.white,
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      SizedBox(
                        child: Wrap(
                          spacing: 10,
                          alignment: WrapAlignment.center,
                          verticalDirection: VerticalDirection.down,
                          children: [
                            Center(
                              child: Text('做饭',
                                  style: TextStyle(
                                      fontFamily: 'PingFangSC-Regular',
                                      fontWeight: FontWeight.normal,
                                      fontSize: 18,
                                      color: ColorUtils.fromHex('#24242C'))),
                            ),
                            Center(
                                child: Text('住家',
                                    style: TextStyle(
                                        fontFamily: 'PingFangSC-Regular',
                                        fontWeight: FontWeight.normal,
                                        fontSize: 14,
                                        color: ColorUtils.fromHex('#8C8C9A'))))
                          ],
                        ),
                      ),
                      Expanded(
                          child: Center(
                        child: Text('4000元/月',
                            style: TextStyle(
                                fontFamily: 'PingFangSC-Regular',
                                fontWeight: FontWeight.normal,
                                fontSize: 18,
                                color: ColorUtils.fromHex('#8C8C9A'))),
                      )),
                      Radio(
                        value: 0,
                        activeColor: ColorUtils.fromHex('#6B8EF6'),
                        groupValue: _singleSelectedIndex,
                        onChanged: (value) {
                          setState(() {
                            _singleSelectedIndex = value!;
                            setState(() {
                              price = 4000;
                            });
                          });
                        },
                      )
                    ],
                  ),
                ),
                Container(
                  height: 54,
                  color: Colors.white,
                  margin: const EdgeInsets.only(top: 10),
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      SizedBox(
                        child: Wrap(
                          spacing: 10,
                          alignment: WrapAlignment.center,
                          verticalDirection: VerticalDirection.down,
                          children: [
                            Center(
                              child: Text('做饭',
                                  style: TextStyle(
                                      fontFamily: 'PingFangSC-Regular',
                                      fontWeight: FontWeight.normal,
                                      fontSize: 18,
                                      color: ColorUtils.fromHex('#24242C'))),
                            ),
                            Center(
                                child: Text('住家',
                                    style: TextStyle(
                                        fontFamily: 'PingFangSC-Regular',
                                        fontWeight: FontWeight.normal,
                                        fontSize: 14,
                                        color: ColorUtils.fromHex('#8C8C9A'))))
                          ],
                        ),
                      ),
                      Expanded(
                        child: Center(
                          child: Text('3000元/月',
                              style: TextStyle(
                                  fontFamily: 'PingFangSC-Regular',
                                  fontWeight: FontWeight.normal,
                                  fontSize: 18,
                                  color: ColorUtils.fromHex('#8C8C9A'))),
                        ),
                      ),
                      Radio(
                        value: 1,
                        groupValue: _singleSelectedIndex,
                        onChanged: (value) {
                          setState(() {
                            _singleSelectedIndex = value!;
                            setState(() {
                              price = 3000;
                            });
                          });
                        },
                      ),
                    ],
                  ),
                ),
                Container(
                  height: 54,
                  color: Colors.white,
                  margin: const EdgeInsets.only(top: 10),
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      SizedBox(
                        child: Text('时长',
                            style: TextStyle(
                                fontFamily: 'PingFangSC-Regular',
                                fontWeight: FontWeight.normal,
                                fontSize: 18,
                                color: ColorUtils.fromHex('#24242C'))),
                      ),
                      Expanded(
                        flex: 1,
                        child: TextField(
                          decoration: const InputDecoration(
                              hintText: '请输入', border: InputBorder.none),
                          textInputAction: TextInputAction.none,
                          textAlign: TextAlign.center,
                          keyboardType: TextInputType.number,
                          textDirection: TextDirection.ltr,
                          style: TextStyle(
                              fontFamily: 'PingFangSC-Regular',
                              fontWeight: FontWeight.normal,
                              fontSize: 18,
                              color: ColorUtils.fromHex('#24242C')),
                          onChanged: (value) {
                            setState(() {
                              month = int.parse(value);
                            });
                          },
                        ),
                      ),
                      SizedBox(
                        child: Text('月',
                            style: TextStyle(
                                fontFamily: 'PingFangSC-Regular',
                                fontWeight: FontWeight.normal,
                                fontSize: 18,
                                color: ColorUtils.fromHex('#8C8C9A'))),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: Container(
        height: 68,
        color: Colors.white,
        alignment: Alignment.center,
        child: MaterialButton(
            onPressed: () {
              var map = <String, int>{};
              map['month'] = month;
              map['price'] = price;
              Navigator.of(context).pop(map);
            },
            height: 48,
            minWidth: 153,
            color: ColorUtils.fromHex('#3D7EFE'),
            shape: const RoundedRectangleBorder(
                side: BorderSide.none,
                borderRadius: BorderRadius.all(Radius.circular(5))),
            child: const Text(
              '确定',
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                  fontWeight: FontWeight.normal,
                  fontFamily: 'PingFangSC-Regular'),
            )),
      ),
    );
  }
}
